package com.ly.demo.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@RestController
public class RedisController {
    @Resource
    private RedisTemplate redisTemplate;

    @GetMapping("/publish")
    public String publishMessage(@RequestParam String message) {
        redisTemplate.convertAndSend("channel1","HELLO");
        return "Message published";
    }
    @GetMapping("/keys")
    public String keys(){
        redisTemplate.opsForValue().set("frontQrCodeMsg:test1", "test");
        redisTemplate.opsForValue().set("frontQrCodeMsg:test2", "test");

        String prefix = "frontQrCodeMsg:";

        Set<String> keys = redisTemplate.keys(prefix + "*");
        System.out.println(keys);
        return keys.toString();
    }
}
